package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.CommentMapper;
import com.situ.springboot.pojo.entity.Comment;
import com.situ.springboot.pojo.vo.CommentVO;
import com.situ.springboot.service.CommentService;
import com.situ.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;


    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<CommentVO> list = commentMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = commentMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<>(list, totalPage, pageNo, pageSize);
    }


    @Override
    public void deleteById(Integer id) {
        commentMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        commentMapper.deleteAll(ids);
    }

    @Override
    public void add(Comment comment, Integer customId) {

        commentMapper.add(comment, customId);
    }


}
